import java.util.Arrays;

/**
 * @Author: Liu, Yunfeng
 * @DateTime: 2021/8/4 22:32
 * @Description: TODO
 */
public class triangleNumber {
    public static int triangleNumber(int[] nums) {
        if (nums == null || nums.length < 3) {
            return 0;
        }
        Arrays.sort(nums);
        int result = 0;
        int current = 0;
        boolean flag = false;
        for (int i = 2; i < nums.length; i++) {
            for(int j = i-1;j>=1;j--){
                for(int k =1; k<=j;k++){
                    if(nums[j]+nums[j-k]<=nums[i]){
                        break;
                    }else{
                        result++;
                    }
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {2, 2, 3, 4};
        System.out.print(triangleNumber(nums));
    }
}
